<?php
/**
 * product class. Provide all utilities function related to 
 * product table.
 * <u>Note:</u> all $db param in first parameter is ezMySQL object.
 * See ezSQL documentation for more information.
 */
class B_requestBean 
{
   
   
   function countOrder($db)
    {
    	$sql = "SELECT COUNT(r.id) as total FROM ".TBL_REQUEST." r ".
				" ORDER BY r.date DESC";
    			
    	$res = $db->get_row($sql);
    	
    	return $res->total;
    }
    
    function getOrderSharePageAdmin($db,$share,$list)
	{
		$page = isset ( $_GET[$list] ) ? intval ( $_GET[$list] ) : 1;
		$rows_per_page= $share;
		$page_start = ( $page - 1 ) * $rows_per_page;
		$page_end = $page * $rows_per_page;
	
		$strSQL = "SELECT r.*,c.countries_name FROM ".TBL_REQUEST." r ".
				" LEFT JOIN ".TBL_COUNTRY." c ON r.country = c.countries_id ".	
				" ORDER BY r.date DESC LIMIT $page_start, $rows_per_page";
		
		$res = $db->get_results($strSQL);
		
		return $res;
	}
   
   /**
     * Delete a news with inputted id.
     * @param $id the news's id.
     * @return true if delete successfully otherwise return false.
     */
    function deleteOrder($db, $id)
	{
		//Delete product
    	$sql = sprintf("DELETE FROM %1\$s" .
				" where %1\$s.id = '$id'", 
				TBL_REQUEST);

    	$res = $db->query($sql);
    	return $res;
	}
    
	
	
	 function countRegister($db)
    {
    	$sql = "SELECT COUNT(r.id) as total FROM ".TBL_PRE_REGISTER." r ".
				" ORDER BY r.send_date DESC";
    			
    	$res = $db->get_row($sql);
    	
    	return $res->total;
    }
    
    function getRegisterSharePageAdmin($db,$share,$list)
	{
		$page = isset ( $_GET[$list] ) ? intval ( $_GET[$list] ) : 1;
		$rows_per_page= $share;
		$page_start = ( $page - 1 ) * $rows_per_page;
		$page_end = $page * $rows_per_page;
	
		$strSQL = "SELECT r.* FROM ".TBL_PRE_REGISTER." r ".
				" ORDER BY r.send_date DESC LIMIT $page_start, $rows_per_page";
		
		$res = $db->get_results($strSQL);
		
		return $res;
	}
	
	/**
     * Delete a news with inputted id.
     * @param $id the news's id.
     * @return true if delete successfully otherwise return false.
     */
    function deleteRegister($db, $id)
	{
		//Delete product
    	$sql = sprintf("DELETE FROM %1\$s" .
				" where %1\$s.id = '$id'", 
				TBL_PRE_REGISTER);

    	$res = $db->query($sql);
    	return $res;
	}
}
?>